import useRequet, { RespData } from "../hook/network"
import { ElMessage } from 'element-plus'
import { Option } from '../types/index'

import { ref } from 'vue'

const request = useRequet({ path: "" });

// 得到今日就诊全部
export const getAllRecord = () => {
  let num = ref(0)

  return new Promise<number>((resolve, reject) => {
    request.sendRequest({
      address: 'sick/record/getTodayRecordCount',
      params: {},
      success: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取数据' + resp.msg)
        num.value = resp.data
        resolve(num.value)
      },
      fail: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取数据' + resp.msg)
        reject(ElMessage.error(resp.msg))
      },
      method: "GET",
    })
  })
}

// 今日就诊已到
export const getRecordArrived = () => {
  let num = ref(0)

  return new Promise<number>((resolve, reject) => {
    request.sendRequest({
      address: 'sick/record/getTodayRecordComeCount',
      params: {},
      success: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取数据' + resp.msg)
        num.value = resp.data
        resolve(num.value)
      },
      fail: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取数据' + resp.msg)
        reject(ElMessage.error(resp.msg))
      },
      method: "GET",
    })
  })
}

// 今日就诊未到
export const getRecordNoArrived = () => {
  let num = ref(0)

  return new Promise<number>((resolve, reject) => {
    request.sendRequest({
      address: 'sick/record/getTodayRecordUnComeCount',
      params: {},
      success: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取数据' + resp.msg)
        num.value = resp.data
        resolve(num.value)
      },
      fail: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取数据' + resp.msg)
        reject(ElMessage.error(resp.msg))
      },
      method: "GET",
    })
  })
}

// 获取 今日待收费订单数量
export const getToChargeCount = () => {
  let num = ref(0)

  return new Promise<number>((resolve, reject) => {
    request.sendRequest({
      address: 'pay/order/toChargeCount',
      params: {},
      success: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取数据' + resp.msg)
        num.value = resp.data
        resolve(num.value)
      },
      fail: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取数据' + resp.msg)
        reject(ElMessage.error(resp.msg))
      },
      method: "GET",
    })
  })
}

// 获取 今日已收费订单数量
export const getHasChargeCount = async() => {
  let num = ref(0)

  return new Promise<number>((resolve, reject) => {
    request.sendRequest({
      address: 'pay/order/hasChargeCount',
      params: {},
      success: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取数据' + resp.msg)
        num.value = resp.data
        resolve(num.value)
      },
      fail: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取数据' + resp.msg)
        reject(ElMessage.error(resp.msg))
      },
      method: "GET",
    })
  })
}

// 得到今日随访全部
export const getAllAccessLog = () => {
  let num = ref(0)

  return new Promise<number>((resolve, reject) => {
    request.sendRequest({
      address: 'sick/accessLog/getSubCompanyTodayLogCount',
      params: {},
      success: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取数据' + resp.msg)
        num.value = resp.data
        resolve(num.value)
      },
      fail: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取数据' + resp.msg)
        reject(ElMessage.error(resp.msg))
      },
      method: "GET",
    })
  })
}

// 今日随访已完成
export const getAccessLogArrived = () => {
  let num = ref(0)

  return new Promise<number>((resolve, reject) => {
    request.sendRequest({
      address: 'sick/accessLog/getSubCompanyTodayLogCompleteCount',
      params: {},
      success: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取数据' + resp.msg)
        num.value = resp.data
        resolve(num.value)
      },
      fail: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取数据' + resp.msg)
        reject(ElMessage.error(resp.msg))
      },
      method: "GET",
    })
  })
}

// 今日随访未完成
export const getAccessLogNoArrived = () => {
  let num = ref(0)

  return new Promise<number>((resolve, reject) => {
    request.sendRequest({
      address: 'sick/accessLog/getSubCompanyTodayLogUnCompleteCount',
      params: {},
      success: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取数据' + resp.msg)
        num.value = resp.data
        resolve(num.value)
      },
      fail: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取数据' + resp.msg)
        reject(ElMessage.error(resp.msg))
      },
      method: "GET",
    })
  })
}